/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#ifndef __COMMON_TYPES_VECTOR_H
#define __COMMON_TYPES_VECTOR_H

#include "../data.h"
#include "string.h"
#include "../debug.h"

#define Z_VECTOR_SIZE_INIT 32

#define Z_WARNING_VECTOR(v, r) if((v)->content==NULL||(v)->head==NULL||(v)->head<(v)->content||(v)->size==0){Z_WARNING("cannot operate on illegal vector: %s", #v);return r;}

typedef struct 
{
    z_data *content;
    z_data *head;
    unsigned int size;
} _z_vector;

z_data z_vector_new(); //method: create a new vector
z_data *_z_vector_new();
int z_vector_del(z_data *v); // method: delete a vector
int z_vector_push(z_data *v, z_data e); // method: push a z_data to a vector
int _z_vector_push(z_data *v, z_data *e);
z_data z_vector_peek(z_data *v); //method: peek at the front of the vector
z_data *_z_vector_peek(z_data *v);
z_data z_vector_pop(z_data *v); //method: pop the front of the vector off, like a stack
z_data *_z_vector_pop(z_data *v);
z_data *z_vector_at(z_data *v, int idx); //method: get element from a vector at an index 'idx'
int z_vector_size(z_data *v); //method: get the length of a vector
int z_vector_erase(z_data *v, int idx); //method: erase an element from a vector (shifts all elements afterwards back one as well)
int z_vector_insert(z_data *vdst, z_data *vsrc, int idx); //method: insert a vector into another vector at index 'idx'
char **z_vector_to_array(z_data *v); //method: converts a vector to an array
z_data *z_array_to_vector(char **a); //method: conerts an array back to a vector

#endif